﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using ClassLibrary.DAO;
using ClassLibrary.Entity;

public partial class UserControl_ucLogin : System.Web.UI.UserControl
{
    TblCustomersDAO customerDAO = new TblCustomersDAO(Global.CONNECTION_STRING);

    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void cmdLogin_Click(object sender, EventArgs e)
    {
        bool bFlag = false;
        TblCustomers customer = customerDAO.GetCustomer(txtUsername.Text.Trim(), Encryption.EncryptToString(txtPassword.Text));
        try
        {
            if ((customer.Emailaddress == txtUsername.Text) && (customer.Emailpassword == Encryption.EncryptToString(txtPassword.Text)))
            {
                Session[Global.SESSION_LOGGED_USER] = customer;
                bFlag = true;

            }
            else
            {
                lblMessage.Text = "UserName or Password is not available.";
                lblMessage.Visible = true;
            }
        }

        catch (Exception ex)
        {
            Session[Global.SESSION_ERROR] = ex;
            Response.Redirect(Global.ERROR_PAGE, true);
        }
        if (bFlag)
        {
            Response.Redirect("Default.aspx");
        }
    }
}
